// 定义人的接口
interface IPerson {
    // 只读属性
    readonly id: number
    name: string
    age: number
    // 可选属性
    sex?: string
}

const person1: IPerson = {
    id: 1,
    name: 'tom',
    age: 20,
    sex: '男'
}

interface SearchFunc {
    (source: string, subString: string): boolean
}

const mySearch: SearchFunc = function (source: string, sub: string): boolean {
    return source.search(sub) > -1
}

console.log(mySearch('abcd', 'bc'))

/*
类类型: 实现接口
1. 一个类可以实现多个接口
2. 一个接口可以继承多个接口
*/

interface Alarm {
    alert(): any;
}

interface Light {
    lightOn(): void;

    lightOff(): void;
}

class Car implements Alarm {
    alert() {
        console.log('Car alert');
    }
}

class Car2 implements Alarm, Light {
    alert() {
        console.log('Car alert');
    }

    lightOn() {
        console.log('Car light on');
    }

    lightOff() {
        console.log('Car light off');
    }
}

interface LightableAlarm extends Alarm, Light {

}
